package org.devocean.groupbuying.web.backend;

import java.util.List;
import java.util.Map;

import org.devocean.groupbuying.domain.Module;
import org.devocean.groupbuying.service.ModuleService;
import org.devocean.groupbuying.utils.RenderMapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value = { "/gb-cpanel/modules" })
public class ModulesController {
	
	@Autowired
	private ModuleService moduleService;
	
	
	/**
	 * return a Map of all modules in the modelAndView
	 * @author Mohsine DANI
	 * @param 
	 * @return a map of modules
	 */
	@RequestMapping(value="/")
	public  Map<String,? extends Object> index() throws Exception {
		try{

			List<Module> modules = moduleService.getModuleList();
						
			return RenderMapUtils.getMap(modules);

		} catch (Exception e) {

			return RenderMapUtils.getModelMapError("Error retrieving Modules from database.");
		}
	}
	
	

}
